<template>
  <div class="person">
    <h2>这边有一辆{{ car.bard }}，价格{{ car.price }}万</h2>
    <button @click="changeBard">修改汽车品牌</button>
    <button @click="changePrice">修改汽车价格</button>
    <button @click="changeCar">修改汽车</button>
    <ul>
      <li v-for="item in youxi" :key="item.id">{{ item.name }}</li>
    </ul>
    <button @click="changeYouxiName">修改第一个游戏的名字</button>
    <hr>
    <h2>测试：{{ test.a.b.c }}</h2>
    <button @click="changeCstring">修改c的值</button>
  </div>
</template>
<script>
</script>
<script lang="ts" setup name="Person">
import { reactive, ref } from 'vue'
let name = ref('张三')
let car = reactive({
  bard: '奔驰',
  price: 10,
})
function changeCar() {
  // car = { bard: '奥拓', price: 1 }  页面不更新
  // car = reactive({ bard: '奥拓', price: 1 })  页面不更新
  Object.assign(car, { bard: '奥拓', price: 1 })
}
function changeBard() {
  car.bard = '宝马'
}
function changePrice() {
  car.price += 10
}
let youxi = reactive([
  {
    id: 1,
    name: '吃鸡',
  },
  {
    id: 2,
    name: '王者荣耀',
  },
  {
    id: 3,
    name: '英雄联盟',
  },
])
function changeYouxiName() {
  youxi[0].name = 'abd'
  name.value = 'wss'
}
let test = reactive({
  a: {
    b: {
      c: '王雅贞',
    },
  },
})
function changeCstring() {
  test.a.b.c = 'fkajfkdjsafds'
}
</script>

<style scoped>
/* 样式 */
.person {
  background-color: skyblue;
  box-shadow: 0 0 10px;
  border-radius: 10px;
  padding: 20px;
}
button {
  margin: 10px;
}
li {
  line-height: 36px;
  font-size: 20px;
  font-weight: bold;
}
</style>